package cn.map.controller;

import cn.map.entity.CommonResult;
import cn.map.service.RsaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 後溪
 */
@RestController
@RequestMapping("/rsa")
@Slf4j
public class RsaController {

    @Resource
    private RsaService rsaService;

//  public static AtomicInteger count = new AtomicInteger();
    private static AtomicInteger count = new AtomicInteger();

    @RequestMapping("/getKey")
    public CommonResult getKey(String serverKey){
        String publicKey = rsaService.getPublicKey(serverKey.replaceAll(" ","+"));
        log.info("收到公钥--"+count.addAndGet(1));
        return new CommonResult(200,publicKey);
    }

    @RequestMapping("/uploadCoupon")
    public int uploadCoupon(String messageJson){
        return rsaService.uploadCoupons(messageJson);
    }
}
